package com.ny.service.impl;

import com.ny.entity.Device;
import com.ny.mapper.DeviceRepository;
import com.ny.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
    private DeviceRepository deviceRepository;  // 注入MongoDB数据访问接口

    @Override
    public List<Device> findAllDevices() {
        // 调用MongoRepository的默认方法查询所有设备
        return deviceRepository.findAll();
    }
    
    @Override
    public Device addDevice(Device device) {
        // 设置创建时间
        device.setCreated_time(new Date());
        // 保存设备信息到数据库
        return deviceRepository.save(device);
    }
}